const app = getApp(), i = require("../../utils/util.js");

Page({
    data: {
        isActive: 1,
        bannersList: [],//轮播图
        canIUse: wx.canIUse('button.open-type.getUserInfo'),
        page: 1,
        limit: 50,
        museumCode: 'jnsbwg',
        exhibType: 'exhibition.type.always',//展览类型
        exhibitions: [],//展览列表
        imgUrl: app.globalData.imgUrl,
        inputValue: '',//关键词
        nextPage: true,//是否存在下一页数据
    },
    onLoad: function (e) {
        console.log(e,e.museumCode,e.scene)
        if(e.museumCode)app.globalData.museumCode = e.museumCode
        this.getBanner()
        this.getData()
        console.log(this.getTabBar())
    },
    onShow:function(){
        if (typeof this.getTabBar === 'function' &&
            this.getTabBar()) {
            this.getTabBar().setData({
                selected: 0
            })
        }
    },
    showBigImage: function (t) {
        var id = t.currentTarget.id;
        wx.navigateTo({
            url: "/pages/exhibition/exhibition?exhibitionId=" + id
        });
    },
    showTheme: function () {
        this.setData({
            exhibType: 'exhibition.type.always',
            isActive: 1,
            page: 1
        })
        this.getData()
    },
    showtemporary: function () {
        this.setData({
            exhibType: 'exhibition.type.temp',
            isActive: 2,
            page: 1
        })
        this.getData()
    },
    getImg: function (img) {
        return app.globalData.imgUrl + img
    },
    bindKeyInput: function (e) {
        this.setData({
            inputValue: e.detail.value
        })
    },
    search: function (e) {
        console.log("搜索")
        wx.navigateTo({
            url: "/pages/result/result?keyWord=" + this.data.inputValue
        });
    },
    scan: function () {
        var _this = this
        wx.scanCode({
            onlyFromCamera: !0,
            success: function (e) {
                console.log(e)
                const id = e.path.split('scene=')[1]
                wx.navigateTo({
                    url: `/pages/exhibition/detail/detail?id=${id}`
                });
            }
        });
        // wx.scanCode({
        //     onlyFromCamera: !0,
        //     success: function (e) {
        //         console.log(e.result)
        //         wx.navigateTo({
        //             url: "/pages/result/result?antiqueCode=" + e.result
        //         });
        //         // if (console.log("res.result:"), console.log(t), "https://jxbwg.museum-edu.cn/jump_dp.html" == t.result && wx.navigateTo({
        //         //     url: "/pages/index/liuyan"
        //         // }), -1 != t.result.indexOf("https://jxbwg.museum-edu.cn/jump.html")) {
        //         //     var i = decodeURIComponent(t.result);
        //         //     console.log(i);
        //         //     var e = i.split("?");
        //         //     console.log(e);
        //         //     var a = e[1].split("=")[1];
        //         //     console.log(a), wx.navigateTo({
        //         //         url: "/pages/exhibition/exhibit?exhibit_id=" + a
        //         //     });
        //         // }
        //     }
        // });
    },
    getData: function () {
        var _this = this
        wx.showLoading({
            title: "加载中..."
        })
        wx.request({
            url: app.globalData.baseUrl + 'antique3d/wechat/exhibition',
            data: {
                museumCode: app.globalData.museumCode,
                page: this.data.page,
                limit: this.data.limit,
                exhibType: this.data.exhibType
            },
            header: {
                'content-type': 'application/json',
                'Authorization': wx.getStorageSync('token')
            },
            success(res) {
                console.log(11111,res.data)
                if(res.data.status==40301 || res.data.status==40101){
                    wx.removeStorageSync('phoneNumber')
                    _this.selectComponent('#vanpopup').getpopupstate()
                }else{
                    let result = res.data.data.rows
                    // console.log('result',result)
                    // 分页获取用
                    // result.length===0?_this.setData({
                    //   nextPage:false
                    // }):_this.setData({
                    //   nextPage:true
                    // })
                    // _this.setData({
                    //     exhibitions: [..._this.data.exhibitions,...result]
                    // })
                    _this.setData({
                        exhibitions: result
                    })
                }
                wx.hideLoading()
            }
        })
    },
    getBanner: function () {
        var _this = this
        wx.request({
            url: app.globalData.baseUrl + 'portal/front/slot',
            data: {
                museumCode: app.globalData.museumCode,
                slotName:app.globalData.slotName
            },
            header: {
                'content-type': 'application/json'
            },
            success(res) {
                console.log(res)
                if(res.data.status==200){
                    if(res.data.data.rows && res.data.data.rows.length>0){
                        _this.setData({
                            bannersList: res.data.data.rows[0].adDetails
                        })
                    }
                }
            }
        })
    },
    /**
 * 页面上拉触底事件的处理函数
 */
    // onReachBottom: function () {
    //     console.log('上拉')
    //     let page = this.data.page + 1
    //     console.log(page)
    //     this.setData({
    //         page: page
    //     })
    //     this.data.nextPage ? this.getData() : console.log('无数据')
    // },

});